# Python 2.6.4
# Project Euler, Problem 106
# Copyright 2010 Talha Zaman

def subsets(s, l):
    if l==1: return [[d] for d in s]
    elif l==0: return [[]]
    elif l<0: return []
    subs = []
    for i in range(len(s)):
        for j in subsets(s[i+1:], l-1):
            subs.append([s[i]] + j)
    return subs

def check(s):
    count = 0
    for i in range(2, 1+len(s)/2):
        for A in subsets(s, i):
            diff = [x for x in s if x > A[0] and x not in A]
            for B in subsets(diff, i):
                count += any(A[j]>=B[j] for j in range(i))
#                comp = False
#                for j in range(i):
#                    if A[j]>=B[j]:
#                        comp = True
#                        break
#                count += comp
    return count

from time import clock
import psyco
psyco.full()
start = clock()
ans = check(range(12))
stop = clock()
print ans, stop-start
